import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# plt.rcParams['font.sans-serif'] = ['SimHei']  # 黑体支持中文
# 两个学院
data = np.array([
    [2549, 0.73, 608],
    [2497, 0.67, 411],
    [2237, 0.65, 308]
])

max_vals = data.max(axis=0)
normalized_data = data / (max_vals + 0.02)

colors = sns.color_palette("husl", 3)

# labels = ['上课时间波动性', '教室空闲率', '节间换教学楼距离']
labels = ['Fluctuation in hours', 'Classroom vacancy rate', 'Distance of inter-section change of building']
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()

fig, ax = plt.subplots(figsize=(12, 8), subplot_kw={'projection': 'polar'})

algorithms = ['MOPSO', 'NSGA-II', 'MOGRO']

for i, alg_data in enumerate(normalized_data):
    values = np.concatenate((alg_data, [alg_data[0]]))
    ax.plot(angles + [angles[0]], values, color=colors[i], label=algorithms[i], linewidth=2)
    ax.fill(angles + [angles[0]], values, color=colors[i], alpha=0.3)

ax.set_xticks(angles)
ax.set_xticklabels([''] * len(labels))  # 清空默认 xticklabels
# ax.set_xticklabels(labels, fontsize=14, fontname="SimHei", va='center', ha='center')
# ax.tick_params(axis='x', pad=40)  # 让标签远离图形

# 让文本对齐角度
# label_distances = [1.37, 1.22, 1.27]  # 设定每个标签的距离（调整 r 值）
label_distances = [1.5, 1.3, 1.32]  # 设定每个标签的距离（调整 r 值）
for i, (label, angle, r) in enumerate(zip(labels, angles, label_distances)):
    ax.text(angle, r, label, fontsize=16, fontname="SimHei",
            ha='center', va='center', rotation=0)

ax.set_ylim(0, 1.1)  # 增大雷达图范围
ax.set_yticklabels([])
ax.legend(loc='upper right', bbox_to_anchor=(1.2, 1.1), prop={'size': 14, 'family': 'Times New Roman'})

plt.show()
